package com.ruoyi.web.controller.order.mapper;

import com.ruoyi.common.core.dao.BaseMapper;
import com.ruoyi.common.entity.DO.order.MemberRechargeOrderDO;
import com.ruoyi.common.entity.VO.order.MemberRechargeOrderVO;
import com.ruoyi.common.entity.VO.order.ShopOrderSearchVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

public interface IBackMemberRechargeOrderMapper extends BaseMapper<MemberRechargeOrderDO> {

    List<MemberRechargeOrderVO> searchList(ShopOrderSearchVO searchVO);

    @Select("SELECT id,member_id memberId FROM member_recharge_order WHERE order_status=0 and pay_status=0 and DATE_FORMAT(create_time, '%Y-%m-%d %H:%M')<=#{yesterday}")
    List<MemberRechargeOrderDO> selectPayExpiredOrderList(String yesterday);

    @Update("UPDATE member_recharge_order set pay_status = #{payStatus} WHERE order_sn = #{orderSn}")
    int updatePayStatusByOrderSn(@Param("orderSn") String orderSn, @Param("payStatus") Integer payStatus);

    @Select("SELECT COUNT(1) FROM  member_recharge_order WHERE order_sn = #{orderSn} and order_status=10 and pay_status=2")
    int checkIsValidRefund(String orderSn);

    @Select("SELECT SUM(amount) FROM member_recharge_order WHERE shop_id=#{shopId} and order_status=3 and pay_status=1")
    BigDecimal sumTotalAmount(Long shopId);

    @Select("SELECT SUM(gift_amount) FROM member_recharge_order WHERE shop_id=#{shopId} and order_status=3 and pay_status=1")
    BigDecimal sumGiftAmount(Long shopId);
}
